#=============================================================================
# Copyright (c) @current_year@, NVIDIA CORPORATION.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#=============================================================================

#[=======================================================================[.rst:
Find@_RAPIDS_PKG_NAME@
--------

Find @_RAPIDS_PKG_NAME@

Imported targets
^^^^^^^^^^^^^^^^

This module defines the following :prop_tgt:`IMPORTED` target(s):

``@_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@``
  The @_RAPIDS_PKG_NAME@ library, if found.

Result variables
^^^^^^^^^^^^^^^^

This module will set the following variables in your project:

``@_RAPIDS_PKG_NAME@_FOUND``
  True if @_RAPIDS_PKG_NAME@ is found.
``@_RAPIDS_PKG_NAME@_INCLUDE_DIRS``
  The include directories needed to use @_RAPIDS_PKG_NAME@.
``@_RAPIDS_PKG_NAME@_LIBRARIES``
  The libraries needed to use@_RAPIDS_PKG_NAME@.
``@_RAPIDS_PKG_NAME@_VERSION_STRING``
  The version of the @_RAPIDS_PKG_NAME@ library found. [OPTIONAL]

#]=======================================================================]

# Prefer using a Config module if it exists for this project

@_RAPIDS_FIND_INITIAL_CODE_BLOCK@

set(@_RAPIDS_PKG_NAME@_NO_CONFIG @_RAPIDS_NO_CONFIG@)
if(NOT @_RAPIDS_PKG_NAME@_NO_CONFIG)
  find_package(@_RAPIDS_PKG_NAME@ CONFIG QUIET)
  if(@_RAPIDS_PKG_NAME@_FOUND)
    find_package_handle_standard_args(@_RAPIDS_PKG_NAME@ DEFAULT_MSG @_RAPIDS_PKG_NAME@_CONFIG)
    return()
  endif()
endif()

find_path(@_RAPIDS_PKG_NAME@_INCLUDE_DIR NAMES @_RAPIDS_HEADER_NAMES@ @_RAPIDS_PATH_SEARCH_ARGS@)

set(@_RAPIDS_PKG_NAME@_IS_HEADER_ONLY @_RAPIDS_HEADER_ONLY@)
if(NOT @_RAPIDS_PKG_NAME@_LIBRARY AND NOT @_RAPIDS_PKG_NAME@_IS_HEADER_ONLY)
  find_library(@_RAPIDS_PKG_NAME@_LIBRARY_RELEASE NAMES @_RAPIDS_PKG_LIB_NAMES@ NAMES_PER_DIR @_RAPIDS_LIB_SEARCH_ARGS@)
  find_library(@_RAPIDS_PKG_NAME@_LIBRARY_DEBUG   NAMES @_RAPIDS_PKG_LIB_DEBUG_NAMES@   NAMES_PER_DIR @_RAPIDS_LIB_SEARCH_ARGS@)

  include(${CMAKE_ROOT}/Modules/SelectLibraryConfigurations.cmake)
  select_library_configurations(@_RAPIDS_PKG_NAME@)
  unset(@_RAPIDS_PKG_NAME@_FOUND) #incorrectly set by select_library_configurations
endif()

include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake)

if(@_RAPIDS_PKG_NAME@_IS_HEADER_ONLY)
  find_package_handle_standard_args(@_RAPIDS_PKG_NAME@
                                    FOUND_VAR @_RAPIDS_PKG_NAME@_FOUND
                                    REQUIRED_VARS @_RAPIDS_PKG_NAME@_INCLUDE_DIR
                                    VERSION_VAR @_RAPIDS_VERSION@)
else()
  find_package_handle_standard_args(@_RAPIDS_PKG_NAME@
                                    FOUND_VAR @_RAPIDS_PKG_NAME@_FOUND
                                    REQUIRED_VARS @_RAPIDS_PKG_NAME@_LIBRARY @_RAPIDS_PKG_NAME@_INCLUDE_DIR
                                    VERSION_VAR @_RAPIDS_VERSION@)
endif()

if(@_RAPIDS_PKG_NAME@_FOUND)
  set(@_RAPIDS_PKG_NAME@_INCLUDE_DIRS ${@_RAPIDS_PKG_NAME@_INCLUDE_DIR})

  if(NOT @_RAPIDS_PKG_NAME@_LIBRARIES)
    set(@_RAPIDS_PKG_NAME@_LIBRARIES ${@_RAPIDS_PKG_NAME@_LIBRARY})
  endif()

  if(NOT TARGET @_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@)
    add_library(@_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ UNKNOWN IMPORTED GLOBAL)
    set_target_properties(@_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ PROPERTIES
      INTERFACE_INCLUDE_DIRECTORIES "${@_RAPIDS_PKG_NAME@_INCLUDE_DIRS}")

    if(@_RAPIDS_PKG_NAME@_LIBRARY_RELEASE)
      set_property(TARGET @_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ APPEND PROPERTY
        IMPORTED_CONFIGURATIONS RELEASE)
      set_target_properties(@_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ PROPERTIES
        IMPORTED_LOCATION_RELEASE "${@_RAPIDS_PKG_NAME@_LIBRARY_RELEASE}")
    endif()

    if(@_RAPIDS_PKG_NAME@_LIBRARY_DEBUG)
      set_property(TARGET @_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ APPEND PROPERTY
        IMPORTED_CONFIGURATIONS DEBUG)
      set_target_properties(@_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ PROPERTIES
        IMPORTED_LOCATION_DEBUG "${@_RAPIDS_PKG_NAME@_LIBRARY_DEBUG}")
    endif()

    if(NOT @_RAPIDS_PKG_NAME@_LIBRARY_RELEASE AND NOT @_RAPIDS_PKG_NAME@_LIBRARY_DEBUG)
      set_property(TARGET @_RAPIDS_PKG_NAME@::@_RAPIDS_PKG_NAME@ APPEND PROPERTY
        IMPORTED_LOCATION "${@_RAPIDS_PKG_NAME@_LIBRARY}")
    endif()
  endif()
endif()

@_RAPIDS_FIND_FINAL_CODE_BLOCK@

unset(@_RAPIDS_PKG_NAME@_NO_CONFIG)
unset(@_RAPIDS_PKG_NAME@_IS_HEADER_ONLY)
